<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/4/14
 * Time: 14:08
 */

namespace app\admin\controller;
use app\admin\Controller;
use app\common\model\StickPic as modelSp;
//\think\Loader::import('controller/Controller', \think\Config::get('traits_path'), EXT);

class StickPic extends Controller{

//    use \app\admin\traits\controller\Controller;
    public function index() {

        $where = [
            'sp.isdelete' => 0
        ];
        $keyword = $this->request->param('keyword');

        $listRows = 20;
        $filed = "sp.*,su.name, su.head,su.phone";
        $model = new modelSp();
        $list = $model->getStickList($where, $filed, $listRows, $this->request, $keyword);

        $this->view->assign('list', $list);
        $this->view->assign("count", $list->total());
        $this->view->assign("page", $list->render());
        $this->view->assign('numPerPage', $list->listRows());

        return $this->view->fetch();
    }

    /**
     * 拒绝
     */
    public function forbid() {

        if ($this->request->method() == "POST") {

            $id = $this->request->param('id', '');
            $where = [
                'id' => $id,
                'isdelete' => 0
            ];
            $data = [
                'status' => 2
            ];

            $model = new modelSp();
            $res = $model->updateStatus($where, $data);

            if ($res) {
                return [
                    'msg' => '成功',
                    'code' => 200,
                    'data' => []
                ];
            } else{
                return [
                    'msg' => '失败',
                    'code' => 404,
                    'data' => []
                ];
            }
        }
    }

    /**
     * 通过
     */
    public function resume(){
        if ($this->request->method() == "POST") {

            $id = $this->request->param('id', '');
            $user_id = $this->request->param('user_id', '');
            $where = [
                'id' => $id,
                'isdelete' => 0
            ];

            $data = [
                'status' => 1
            ];

            $model = new modelSp();
            $res = $model->updateStatus($where, $data);

            if ($res) {
                $where = [
                    'user_id' => $user_id,
                    'isdelete' => 0
                ];
                $res1 = $model->updateUserCoin($where);
                if ($res1) return [
                    'msg' => '审核成功',
                    'code' => 200,
                    'data' => []
                ];
                else return [
                    'msg' => '审核失败',
                    'code' => 404,
                    'data' => []
                ];
            } else{
                return [
                    'msg' => '审核失败',
                    'code' => 404,
                    'data' => []
                ];
            }
        }
    }

}